<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<s:url value="/css/style.css"/>" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<s:url value="/js/jquery.js"/>"></script>
<script type="text/javascript" src="<s:url value="/js/common.js"/>"></script>
<script type="text/javascript" src="<s:url value="/js/ajaxfileupload.js"/>"></script>
<script type="text/javascript" src="<s:url value="/js/jquery.validate.js"/>"></script>
<script type="text/javascript">
var rootUrl = '<s:url value="/" />';
var imgURL = '<s:url value="/img/del.gif" />';
function doSubmit(){
	 
	if(window.confirm('Save modify?')) {
	// here is validate form . 
	
	$('#editForm').submit();
	}
}
function goBack(){
	location.href='<s:url value="/data/FAQ/list"/>';
}
 
function upload(){
	if(!$('#file').val()){
		alert('Please select a file.'); return ;
	}
	$.ajaxFileUpload({
		url:'<s:url value="/file/Upload/upload" />',
		secureuri:false,
		fileElementId:'file',
		dataType : 'json',
		success: function (data,status)
		{
		
		   var r = eval('(' + [data.replace(/(<pre>)|(<\/pre>)/gi,'')] + ')');
		   if(r.realName!='null'){
			$('#xxx').hide();
			$('#attachmentIds').val($('#attachmentIds').val()+','+r.id);    
		   var tbContent = '<tr><td><a href=\"'+rootUrl+r.realName+'\">'+r.name+'</a></td><td>&nbsp;&nbsp;<img style="cursor:pointer" src="'+imgURL+'" onclick="javascript:delfile(this,'+r.id+');"  alt="删除" /></td></tr>';
		    
		   $('#fileListTb').children('tbody').append(tbContent); 
		   }else{
			$('#xxx').text(r.sizeMsg).show();
			
		   }
			
		},
		error: function (data, status, e)
		{
			alert('upload file error !');
		}
		});
}
function delfile(obj,id){
    var oRow = obj.parentNode.parentNode; 
	oRow.parentNode.removeChild(oRow);
	$.ajax({
		url:'<s:url value="/file/Upload/delete" />',
		data:{'id':id},
		success: function(){
		
			}
		});
}
$(function(){
	$('#editForm').validate();
	if($.trim($('#result').text())!=''){
		popupDiv('pop-div');
	}
});

</script>
<title><s:text name="system.title" /></title>
</head>
<body>
<s:include value="/common/up.jsp"></s:include>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td class="box">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td id="tag-over"><span id="tag-over">FAQ</span></td>
				<td class="tab3-line" width="90%">&nbsp;</td>
			</tr>
		</table>
		<s:form  action="FAQ/save" namespace="/data" method="post" id="editForm" name="editForm" enctype="multipart/form-data">
		<s:hidden name="id"></s:hidden>
		<s:hidden name="attachmentIds" id="attachmentIds"></s:hidden>
		<table width="100%" border="0" cellpadding="3" cellspacing="1" class="margin">
			<tr>
				<td align="right" width="35%" class="tablecolour5">Question<font color="red">*</font>:</td>
				<td width="50%" class="tablecolour5"><s:textarea name="question" cssClass="input2 required" rows="5" cols="35" /></td>
			</tr>
			<tr>
				<td align="right" class="tablecolour5">Answer<font color="red">*</font>:</td>
				<td class="tablecolour5"><s:textarea name="answer" cssClass="input2 required" rows="5" cols="35"/></td>
			</tr>
			<tr>
				<td align="right" class="tablecolour5">Attachments:</td>
				<td class="tablecolour5">
				<table border="0" cellpadding="1" cellspacing="1" id="fileListTb" >
					<tbody>
					<s:iterator value="attachs">
					 <tr>
					 <td><a href="<s:property value="realName" />"><s:property value="name" /></a>&nbsp;</td><td><img src="<s:url value="/img/del.gif"/>" onclick="delfile(this,'<s:property value="id"/>')" style="cursor:pointer;" /></td>
					 </tr>
					 </s:iterator>
					</tbody>
				</table>
				<s:file name="file" id="file"   /><input  type="button" value="Upload"  onclick="upload()" /><label id="xxx" class="error"></label>
				
				</td>
			</tr>
		<tr>
			<td align="center" colspan="2" height="50" class="tablecolour5">
			<input name="reset" type="reset" class="btn1" value="Reset" />
			<input type="button" class="btn1" value="Save"  onclick="doSubmit();"  /> 
			<input name="goback" type="button" class="btn1"
				value="Go Back" onclick="goBack()" /></td>
		</tr>
		</table>
		</s:form>
		</td>
	</tr>
</table>
<s:include value="/common/down.jsp"></s:include>
<div id='pop-div' style="width: 300px;" class="pop-box">  
  <s:include value="/common/confirm.jsp"></s:include>   
</div>

</body>
</html>